'The Program Entry Point
' $HeadURL: http://gabbscript.googlecode.com/svn/branches/funcbranch/Gabbscript/Main.vb $
' $Author: brookjensen500@hotmail.com $
' $Revision: 72 $
' $Date: 2007-11-05 19:35:19 +0000 (Mon, 05 Nov 2007) $

Imports Gabbscript.Parser

Module Main

    Sub Main(ByVal args() As String)
        Dim fileName As String = ""

        'Initialize script
        Dim s As Script = New Script()

        'Register Module Functions
        AndrewFunctions.RegisterFunctions(s.funcList)
        BrendanFunctions.RegisterFunctions(s.funcList)

        'Check the amount of arguments
        If args.Length = 0 Then

            Console.WriteLine("Enter a filename to load, or type console! :)")
            'Ask the user for a file to load
            fileName = Console.ReadLine()
            Console.WriteLine()
        Else
            'Filename is first program parameter
            fileName = args(0)
        End If

        If fileName.ToLower() = "console" Then
            Console.WriteLine("Entering console mode :P")
            Console.WriteLine("Type gabbEnd to finish parsing")

            Dim line As String = Console.ReadLine()
            Dim lines As ArrayList = New ArrayList()

            Do While line <> "gabbEnd"
                lines.Add(line)
                line = Console.ReadLine()
            Loop

            Console.WriteLine()

            s.SetLines(lines)
        Else
            'Load the file
            s.LoadFile(fileName)
        End If

        

        'Parse the file
        s.ParseFile()

        'Run the code :)
        s.Run()
    End Sub

End Module
